//
//  VerifyRealNameEngine.m
//  HuLaQuan
//
//  Created by hok on 1/30/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "VerifyRealNameEngine.h"

#import "CurrentUser.h"

@implementation VerifyRealNameEngine

- (void)verifyRealName:(NSString *)name cardInfo:(NSDictionary *)cardInfo identity:(NSString *)identity
{
    NSString *randomKey = [self createKeyWithLength:24];
    
    NSString *src = [NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\"?><msg service=\"realNameAuth\" sysName=\"attach\" sign=\"RSA\" serialNumber=\"%@\" termId=\"star_open_esa\" termAdd=\"23.23,23.45\" termBrand=\"iPhone\" osVersion=\"iPhone OS 9.1\" appVersion=\"1.0.0\" tokenValue=\"%@\" userId=\"%@\" channelId=\"88888888\"><customerNm>%@</customerNm><cardNo>%@</cardNo><accType>%@</accType><certifId>%@</certifId><cvn2></cvn2><expired></expired><attach>attach</attach></msg>",[self getSerialNumber],[CurrentUser sharedInstance].token,[CurrentUser sharedInstance].ID,name,cardInfo[@"cardId"],cardInfo[@"accType"]? cardInfo[@"accType"] : @"",identity];
    //
    NSLog(@"%@ -- src --- ",src);
    
    NSString *final = [NSString stringWithFormat:@"%@|%@|%@",[self firstString],[self secondStringWithKey:randomKey],[self thirdStringWithBody:src andKey:randomKey]];
 
    [YuHTTPClient XMLDataWithUrl:SERVER_HOST_CASHIER parameters:final success:^(BOOL isSuccess, id item){
        
        NSDictionary *result;
        if (isSuccess) {
            result = @{@"isSuccess":@YES};
        }else{
            NSLog(@"%@",item);
            result = @{@"isSuccess":@NO,@"message":item};
        }
        [[NSNotificationCenter defaultCenter] postNotificationName:@"VerifyRealNameFinish" object:result];
    }];
}
@end
